<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="__PUBLIC__/echarts/echarts.min.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
</head>
<style>

    .layui-table th, .layui-table td{
        padding: 9px 6px;
        text-align: center;
    }
    .operation-menu a{
        margin: 5px 0;!important;
    }
    .layui-form-item{
        margin-bottom:0px;
    }
    .layui-input-block{
        margin-left: 0px;
        min-height: 0px;
    }
    .layui-table[lay-skin=line] td, .layui-table[lay-skin=line] th {
        max-width: 300px;
    }
    /*.layui-form select{*/
    /*display: inline-block;*/
    /*}*/
</style>
<body>
<div class="layui-fluid main">
    <fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;border:0">
        <div class="layui-form-item" style="float: left;">
            <form id="form1" class="layui-form serch" action="{:url('admin/goods/index')}" method="post">
                <div class="layui-form-item" style="float: left;">
                    <div class="layui-input-inline">
                        <input type="text" name="keywords" lay-verify="title" autocomplete="off" placeholder="商品ID / 商品名称 / 产品Code" value="{if isset($where['keywords'])}{$where['keywords']}{/if}" class="layui-input layui-btn-sm">
                    </div>

                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="city_id" lay-search="">
                                <option value="">城市</option>
                                {volist name='city' id='vo'}
                                <option value="{$vo.id}" {if  isset($where['city_id']) AND $vo.id==$where['city_id'] } selected{/if}>{$vo.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>

                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="classify_id" lay-search="">
                                <option value="">商品分类</option>
                                {volist name='classify' id='vo'}
                                <option value="{$vo.classify_id}" {if  isset($where['classify_id']) AND $vo.classify_id==$where['classify_id']} selected{/if}>{$vo.classify_name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>




                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="goods_status" lay-search="">
                                <option value="">商品状态</option>
                                <option value="1" {if  isset($where['goods_status']) AND $where['goods_status']=='1'} selected{/if}>售卖中</option>
                                <option value="2" {if  isset($where['goods_status']) AND $where['goods_status']=='2'} selected{/if}>未售买</option>
                                <option value="3" {if  isset($where['goods_status']) AND $where['goods_status']=='3'} selected{/if}>已售罄</option>

                            </select>
                        </div>
                    </div>

                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="supplier_id" lay-search="">
                                <option value="" >供应商</option>
                                <option value="999999"  {if  isset($where['supplier_id']) AND "999999"==$where['supplier_id']} selected{/if}>自营</option>
                                {volist name='supplier' id='vo'}
                                <option value="{$vo.id}" {if  isset($where['supplier_id']) AND $vo.id==$where['supplier_id']} selected{/if}>{$vo.name}</option>
                                {/volist}
                                <option value="1000000" {if  isset($where['supplier_id']) AND "1000000"==$where['supplier_id']} selected{/if}>其他</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="orderType" lay-search="">
                                <option value="" >订单类型</option>
                                {volist name='orderType' id='vo'}
                                <option value="{$vo.type}" {if  isset($where['orderType']) AND $vo.type==$where['orderType']} selected{/if}>{$vo.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="updSellTime" lay-search="">
                                <option value="" >价格套餐</option>
                                <option value="1" {if isset($where['updSellTime']) AND $where['updSellTime']=='1'}selected{/if}>未设置</option>
                                <option value="0" {if isset($where['updSellTime']) AND $where['updSellTime']=='0'}selected{/if}>已设置</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="isTob" lay-search="">
                                <option value="" >Tob上架状态</option>
                                <option value="1" {if isset($where['isTob']) && $where['isTob']==1}selected{/if}>已上架</option>
                                <option value="2" {if isset($where['isTob']) && $where['isTob']==2}selected{/if}>未上架</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-danger layui-btn-sm" lay-submit="" lay-filter="serch">搜索</button>
                            <button type="reset" class="layui-btn layui-btn-danger layui-btn-sm clear_form">重置</button>
                        </div>
                    </div>
                    <div class="layui-input-inline" style="margin-left:-20px;">
                        <div class="layui-inline">
                            <a href="{:url('admin/goods/addgoods')}" class="layui-btn layui-btn-sm a_menu">
                                新增商品
                            </a>
                            <a href="{:url('admin/goods/index')}?exportFlag=1" class="layui-btn layui-btn-default layui-btn-sm">导出Excel</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>
    <table class="layui-table" lay-even="" lay-skin="line">
        <colgroup>
            <col width="8%">
            <col width="8%">
            <col width="24%">
            <col width="6%">
            <col width="6%">
            <col width="6%">
            <col width="6%">
            <col width="8%">
            <col width="8%">
            <!--<col width="6%">-->
            <col width="6%">
            <col width="6%">
            <col width="6%">
            <col width="6%">
            <col width="6%">
            <col width="6%">
        </colgroup>
        <thead>
        <tr>
            <th>商品ID</th>
            <th>略缩图</th>
            <th>商品名称</th>
            <th>产品Code</th>
            <th>商品类型</th>
            <th>城市</th>
            <th>商品状态</th>
            <th>开始时间</th>
            <th>结束时间</th>
            <!--<th>发布人员</th>-->
            <th>关联产品</th>
            <th>价格设置</th>
            <th>直订/热门/提醒</th>
            <th>tob状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name='liebiao' id='v'}
        <tr>
            <td>{$v.goods_id}</td>
            <td>
                {notempty name="$v.goods_image"}
                {if $images = array_values(array_filter(explode(',',$v['goods_image'])))}
                <img src="{$images[0]|default=''}" width="64px">
                {/if}
                {/notempty}
            </td>
            <td class="" title="{$v.goods_name}">
                {$v.goods_name}
                <!--{if !empty($v['standard_name']) && ($v['goods_name']!==$v['standard_name'])}-->
                <!--<br><span style="color:red">TOB：{$v.standard_name}</span>-->
                <!--{/if}-->
            </td>
            <td>
                {$v.goods_tcode}
            </td>
            <td>
                {$v.tag_name}
            </td>
            <td>
                {$v.name}
            </td>
            <td>
                {switch name="v.goods_status"}
                {case value=""}未知{/case}
                {case value="1"}售卖中{/case}
                {case value="2"}未售卖{/case}
                {case value="3"}已告罄{/case}
                {default /}default
                {/switch}
                {if $v['is_group']==1}
                <br>
                <span style="color:red">(拼团)<span>
                {/if}
            </td>
            <td>{$v.starttime|date='Y-m-d',###} </td>
            <td>{$v.endtime|date='Y-m-d',###}</td>
            <!--<td>{$v.admin.nickname}</td>-->
            <td>
                {if $v['product_exists']==1}
                <a href="{:url('admin/product/productmake')}?id={$v.product_id}" target="_blank" class="layui-btn layui-btn-xs layui-btn-warm"  style="margin-right: 0;font-size:12px;">跳转产品</a>
                {else}
                未关联产品
                {/if}
            </td>
            <td>{if $v['update_selltime']==1}<span style="color:red">未设置</span>{else}已设置{/if}</td>
            <td>
                <form class="layui-form notice_form" data-id="{$v.goods_id}">
                    <input type="checkbox" name="popular" value="1" lay-filter="popular" lay-skin="switch" <?php if($v['popular']==1){ echo 'checked';} ?> lay-text=" 热门|普通">
                    <input type="checkbox" name="recommend" value="1" lay-filter="recommend" lay-skin="switch" <?php if($v['recommend']==1){ echo 'checked';} ?> lay-text="直订|非直">
                    <input type="checkbox" name="is_ctrip_notice" value="1" lay-filter="is_ctrip_notice" lay-skin="switch" <?php if($v['is_ctrip_notice']==1){ echo 'checked';} ?> lay-text="携程|携程">
                    <input type="checkbox" name="is_fliggy_notice" value="1" lay-filter="is_fliggy_notice" lay-skin="switch" <?php if($v['is_fliggy_notice']==1){ echo 'checked';} ?> lay-text="飞猪|飞猪">
                    <input type="checkbox" name="is_mafengwo_notice" value="1" lay-filter="is_mafengwo_notice" lay-skin="switch" <?php if($v['is_mafengwo_notice']==1){ echo 'checked';} ?> lay-text="马蜂|马蜂">
                </form>
            </td>
            <td>
                {if !empty($v.show_toB) && $v.show_toB==1}
                <span style="color:green">已上架</span>
                {else}
                <span style="color:red">未上架</span>
                {/if}
            </td>
            <td class="operation-menu">
                <a href="{:url('admin/goods/addgoods')}?id={$v.goods_id}" class="layui-btn layui-btn-xs layui-btn-warm a_menu" style="margin-right: 0;font-size:12px;background: darkslategrey">编辑</a>
                <a href="{:url('admin/goods/goodsnoticelog')}?id={$v.goods_id}" class="layui-btn layui-btn-xs layui-btn-normal noticelog" style="margin-right: 0;font-size:12px;">提醒记录</a>

                {if $v['channel_source']!='fareharbor'}

                {if $v['product_price_exists']==1}
                    <a href="{:url('admin/product/productmake')}?id={$v.product_id}" target="_blank" class="layui-btn layui-btn-xs layui-btn-warm" style="margin-right: 0;font-size:12px;">产品价格</a>
                {else}
                    <a href="{:url('admin/goods/addclassify')}?id={$v.goods_id}" class="layui-btn layui-btn-xs layui-btn-warm a_menu" style="margin-right: 0;font-size:12px;background: #51a954">套餐设置</a>
                    {if $v['orderType']=='Vehicle'}
                    <a href="{:url('admin/goods/setproductprice')}?id={$v.goods_id}" class="layui-btn layui-btn-xs layui-btn-warm" style="margin-right: 0;font-size:12px;background: darkslategrey">商品价格</a>
                    {else}
                    <a href="{:url('admin/goods/setgoodsprice')}?id={$v.goods_id}" class="layui-btn layui-btn-xs layui-btn-warm" style="margin-right: 0;font-size:12px;background: darkslategrey">商品价格</a>
                    {/if}
                {/if}

                {/if}
                {switch name="v.goods_status"}
                {case value=""}  {/case}
                {case value="1"} <a href="####" class="layui-btn layui-btn-xs layui-btn-danger shelves" data-id="{$v.goods_status}"  codeid="{$v.goods_id}" style="margin-right: 0;font-size:12px;">下架</a>{/case}
                {case value="2"} <a href="####" class="layui-btn layui-btn-xs layui-btn-danger shelves" data-id="{$v.goods_status}" codetype="{$v.orderType}" codeid="{$v.goods_id}" style="margin-right: 0;font-size:12px;">上架</a>{/case}
                {case value="3"} <a href="####" class="layui-btn layui-btn-xs layui-btn-danger " data-id="{$v.goods_status}" codeid="{$v.goods_id}" style="margin-right: 0;font-size:12px;background: #777777">已售完</a>{/case}
                {default /}default
                {/switch}
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div>{$liebiao->render()}</div>

    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>
    <script>

        layui.use('form', function () {
            var form = layui.form;

            //是否推荐
            form.on('switch(recommend)', function(data){
                var id= $(this).parent().attr('data-id')
                var recommend;
                if(data.elem.checked){
                    recommend =1;
                }else{
                    recommend =0;
                }
                $.ajax({
                    url:"{:url('admin/goods/recommend')}",
                    data:{'id':id,'recommend':recommend},
                    type:'post',
                    async: false,
                    success:function(res) {

                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.reload();
                            },1500)
                        }
                    }
                })

            });
            //是否直订
            form.on('switch(popular)', function(data){
                var id = $(this).parent().attr('data-id');
                var popular;

                if(data.elem.checked){
                    popular =1;
                }else{
                    popular =0;
                }
                $.ajax({
                    url:"{:url('admin/goods/recommend')}",
                    data:{'id':id,'popular':popular},
                    type:'post',
                    async: false,
                    success:function(res) {

                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.reload();
                            },1500)

                        }
                    }
                })

            });
            //携程提醒
            form.on('switch(is_ctrip_notice)', function(data){
                var id = $(this).parent().attr('data-id');
                var value = 0;
                if(data.elem.checked){
                    value =1;
                }
                //函数调用
                notice_callback(id,'is_ctrip_notice',value);
            });
            //飞猪提醒
            form.on('switch(is_fliggy_notice)', function(data){
                var id = $(this).parent().attr('data-id');
                var value = 0;
                if(data.elem.checked){
                    value =1;
                }
                //函数调用
                notice_callback(id,'is_fliggy_notice',value);
            });
            //马蜂窝提醒
            form.on('switch(is_mafengwo_notice)', function(data){
                var id = $(this).parent().attr('data-id');
                var value = 0;
                if(data.elem.checked){
                    value =1;
                }
                //函数调用
                notice_callback(id,'is_mafengwo_notice',value);
            });

            //统一调用方法
            function notice_callback(id,column,value){
                $.ajax({
                    url:"{:url('admin/goods/updOTANotice')}",
                    data:{'id':id,'notice_column':column,'notice_value':value},
                    type:'post',
                    async: false,
                    success:function(res) {
                        layer.msg(res.msg);
                    }
                })
            }
        });



    </script>
    <script>
        var message;
        layui.config({
            base: '__JS__/',
            version: '1.0.1'
        }).use(['app', 'message'], function() {
            var app = layui.app,
                $ = layui.jquery,
                layer = layui.layer;
            //将message设置为全局以便子页面调用
            message = layui.message;
            //主入口
            app.set({
                type: 'iframe'
            }).init();
        });
    </script>
    <script type="text/javascript">

        $('.delete').click(function(){
            var id = $(this).attr('codeid');

            layer.confirm('确定要删除?', function(index) {
                $.ajax({
                    url:"{:url('admin/coupon/delcoupon')}",
                    data:{id:id},
                    success:function(res) {
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.reload();
                            },1500)
                        }
                    }
                })
            })
        });
        $('.shelves').click(function(){
            var id = $(this).attr('codeid');
            var goods_status= $(this).attr('data-id');
            var type_msg = '';
            if(goods_status==2){
                var orderType= $(this).attr('codetype');
                var arr = [ "Vehicle","Custom","Other","Price_Gap","Self_Drive","Personal_Tailor","Subscription" ];
                if($.inArray(orderType,arr) < 0){
                    type_msg = "该类型商品订单可自动建单，是否确定操作？";
                }else{
                    type_msg = "该类型商品订单需手动建单，是否确定操作？";
                }
            }else{
                type_msg = "是否确定操作？";
            }

            layer.confirm(type_msg, function(index) {
                $.ajax({
                    url:"{:url('admin/goods/shelves')}",
                    data:{id:id,goods_status:goods_status},
                    success:function(res) {
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.reload();
                            },1500)
                        }
                    }
                })
            })
        })



        // $('.copy').click(function(){
        //     var id = $(this).attr('codeid');
        //     layer.confirm('确定复制吗?', function(index) {
        //         $.ajax({
        //             url:"{:url('admin/trip/copytrip')}",
        //             data:{id:id},
        //             success:function(res) {
        //                 layer.msg(res.msg);
        //                 if(res.code == 1) {
        //                     setTimeout(function(){
        //                         location.reload();
        //                     },1500)
        //                 }
        //             }
        //         })
        //     })
        // })

    </script>
    <script type="text/javascript">
        layui.use('layer', function(){
            var layer = layui.layer;
            $('.a_menu').click(function(){
                var url = $(this).attr('href');
                var a = 0;
                $.ajax({
                    url:url
                    ,async:false
                    ,success:function(res){
                        if(res.code == 0) {
                            layer.msg(res.msg);
                            a = 1;
                        }
                    }
                })
                if(a === 0) {
                    layer.open({
                        type:2,
                        content:url,
                        area: ['85%', '95%'],
                        end:function(){
                            location.reload();
                        }
                    });
                }
                return false;
            })
            $('.noticelog').click(function(){
                var url = $(this).attr('href');
                layer.open({
                    type:2,
                    title:"提醒事项记录",
                    content:url,
                    area: ['60%', '80%']
                });
                return false;
            })
            $('.preview').click(function(){
                var url = $(this).attr('href');
                layer.open({
                    type:2,
                    content:url,
                    area: ['550px', '400px']
                });
                return false;
            })
            //重置
            $('.clear_form').click(function(){
                $(':input','#form1')
                    .not(':button,:submit,:reset')   //将myform表单中input元素type为button、submit、reset、hidden排除
                    .val('')  //将input元素的value设为空值
                    .removeAttr('checked')
                return false;
            })
        });
    </script>

</body>
</html>
